package com.biz.utils;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;

import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Map;

/*************************************************************************
 * 文件名称 ：EncoderHandler.java                   
 * 描述说明 ：Zxing 构建二维码
 * 
 * 创建信息 : create by 刘佳佳 on 下午3:34:34
 * 修订信息 : modify by ( ) on (date) for ( )
 * 
 * 版权信息 : Copyright (c) 2015 扬州北斗科技有限公司 
 **************************************************************************/

public class EncoderHandler {
	
	public static BufferedImage getQrImage(String content){
		BufferedImage bufimag=null;
		try {
//		     content = "201506473892";
//		     String path = "C:/testImage";
		     MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
		     Map hints = new HashMap();
		     hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
		     BitMatrix bitMatrix = multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, 80, 90,hints);
//		     File file1 = new File(path,"大包裹.jpg");
//		     MatrixToImageWriter.writeToFile(bitMatrix, "jpg", file1);
		     
		     bufimag= MatrixToImageWriter.toBufferedImage(bitMatrix);
		    // ImageIO.write(bufimag, "JPEG", response.getOutputStream());
		 } catch (Exception e) {
		     e.printStackTrace();
		 }
		return bufimag;
	}
	
//	@Test
//	public  void testQrImage(){
//		String content="33333";
//		BufferedImage bufimag=null;
//		try {
//		     String path = "E:/File/qrImage";
//		     MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
//		     Map hints = new HashMap();
//		     hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
//		     BitMatrix bitMatrix = multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, 80, 90,hints);
//		     File file1 = new File(path,"签收.jpg");
//		     MatrixToImageWriter.writeToFile(bitMatrix, "jpg", file1);
//		     
////		     bufimag= MatrixToImageWriter.toBufferedImage(bitMatrix);
////		     ImageIO.write(bufimag, "JPEG", response.getOutputStream());
//		 } catch (Exception e) {
//		     e.printStackTrace();
//		 }
//	}
	



}
